function [varargout] = getstructs(varargin)
% intialize parameters
global CONTROL

if(nargin > 0 && isnumeric(varargin{1}))
    sel = varargin{1};
    k0 = 1; % do this ONE from the selection (e.g., the selected one)
    iargin = nargin - 1;
else % read it from the database.
    sel = getmainselection;
    k0 = 0; % do all in selection;
    iargin = nargin;
end;

if(nargout > nargin - k0)
    f = {CONTROL(sel).filename};
    varargout{nargout} = f; % if requested, put this out
end;

for k = 1:iargin
    s = varargin{k+k0};
%    sel = getmainselection;

    %% get the datasets
    for j = 1:length(sel)
        rem = s;
        a = CONTROL(sel(j));
        sofar = 'a';
        f = fieldnames(a);
        while(~isempty(rem))
            [p, rem] = strtok(rem, '.'); % parse through the string
%            p
            u = strmatch(p, f, 'exact');
            if(~isempty(u) && u > 0)
                b = eval([sofar '.' p]);  % extract the data
                if(isstruct(b)) % what kind is it?
%                    fprintf(1, 'struct found: %s\n', p);
                    sofar = [sofar '.' p]; % get the name so far...
                    f = fieldnames(b); % and find out the names of the substructure!
                elseif(ischar(b) || isnumeric(b) || iscell(b))
                    varargout{k}{j} = b;
                else
                    fprintf(1, 'getstructs: Don''t know about field %s\n', p);
                end;


            end;
        end;
    end;
end;
